import unittest
from page.register_page import RegisterPage,get_driver
from page.login_page import LoginPage
from page.admin_index_page import AdminLoginPage
import time

class RegisterTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开驱动
        driver = get_driver()
        cls.register = RegisterPage(driver)
        cls.login = LoginPage(driver)
    def test_01_register(self):
        # 访问注册地址
        self.register.get(RegisterPage.register_url)
        # 输入必填项
        self.register.username_input('test01')
        self.register.email_input('321@qq.com')
        self.register.password_input('123456')
        self.register.confirm_password_input('123456')
        self.register.phonenumber_input('987654321')
        # 点击立即注册
        self.register.submit_btn()
        time.sleep(2)


        # 验证是否注册成功，然后做断言
        # 访问login页面
        self.login.get(LoginPage.login_url)

        # 获取actual_username
        self.actual_username = self.login.username_text()

        # 断言
        self.assertEqual('test01', self.actual_username)

    @classmethod
    def tearDownClass(cls) -> None:
        # 删除新增会员
        driver = get_driver()
        cls.admin_index = AdminLoginPage(driver)
        cls.admin_index.get(AdminLoginPage.adminloginpage_url)
        cls.admin_index.login()
        cls.admin_index.menber_management_click()
        cls.admin_index.delete_menber()

        # 关闭资源句柄
        cls.admin_index.page_quit()
        cls.register.page_quit()
        cls.login.page_quit()




if __name__ == '__main__':
    unittest.main(verbosity=2)